

#include <iostream>

class Resources {
public:

	friend std::ostream& operator<<(std::ostream& out, const Resources& A);

	Resources() : data(nullptr), size(0)
	{
		std::cout << "default construct" << std::endl;
	}

	Resources(int size) : data(new int[size]), size(size)
	{
		for (int i = 0; i < size; i++) {
			data[i] = 0;
		}
		std::cout << "size construct" << std::endl;
	}

	Resources(int size, int num) : data(new int[size]), size(size)
	{
		for (int i = 0; i < size; i++) {
			data[i] = num;
		}
		std::cout << "size/sum construct" << std::endl;
	}

	Resources(Resources&& other) noexcept : data(other.data), size(other.size)
	{
		other.data = nullptr;
		other.size = 0;
		std::cout << "move construct" << std::endl;
	}

	Resources(Resources& other)
	{
		data = new int[other.size];
		for (int i = 0; i < other.size; i++) {
			data[i] = other.data[i];
		}
		size = other.size;
		std::cout << "copy construct" << std::endl;
	}

	Resources& operator=(Resources&& other) noexcept
	{
		if (this != &other) {
			delete[] data;
			data = other.data;
			size = other.size;
			other.data = nullptr;
			other.size = 0;
		}
		std::cout << "move operater =" << std::endl;
		return *this;
	}

	Resources& operator=(Resources& other)
	{
		delete[] data;
		data = new int[other.size];
		for (int i = 0; i < other.size; i++) {
			data[i] = other.data[i];
		}
		size = other.size;
		std::cout << "copy operater =" << std::endl;
		return *this;
	}

	~Resources()
	{
		std::cout << "destructor" << std::endl;
		delete[] data;
	}
private:
	int* data;
	int size;
};

std::ostream& operator<<(std::ostream& out, const Resources& A)
{
	for (int i = 0; i < A.size; i++)
	{
		out << A.data[i] << " ";
	}
	return out;
}

int main(void)
{
	Resources R1(10);
	std::cout << "1. " << R1 << std::endl;

	Resources R2 = std::move(R1);
	std::cout << "2. " << R1 << std::endl;
	std::cout << "2. " << R2 << std::endl;
	R1 = std::move(R2);
	std::cout << "2. " << R1 << std::endl;
	std::cout << "2. " << R2 << std::endl;

	Resources R3(0);
	std::cout << "3. " << R3 << std::endl;

	Resources R4 = 20;
	std::cout << "4. " << R4 << std::endl;
	R4 = 10;
	std::cout << "4. " << R4 << std::endl;

	Resources R5 = { 10,20 };
	std::cout << "5. " << R5 << std::endl;
	R5 = { 10,30 };
	std::cout << "5. " << R5 << std::endl;
	R5 = R4;
	std::cout << "5. " << R5 << std::endl;

	Resources R6 = R5;
	std::cout << "6. " << R6 << std::endl;

	Resources R7(R6);
	std::cout << "7. " << R7 << std::endl;

	return 0;
}

